<?php

/**
 * Description of BaseController
 *
 * @author gun
 */
require_once 'AppRegistry.php';
require_once 'SecureController.php';
class Admin_BaseController extends Admin_SecureController {
    
    private $_http;
    private $_session;
//    public static $_bcObj;
    
    public function init() {
        parent::init();
        
        /**
         * WHEN WE LEAVE resource-parameter page,
         * destroy session resource parameter
         * 
         */
        
        if ('resource-parameter' !== $this->getRequest()->getControllerName()) {
            if(!$this->_session)
                $this->_session = new Zend_Session_Namespace('Web_Resource_Param');
        
            if (!Zend_Session::isDestroyed('resource_id'))
                unset($this->_session->resource_id);
        }
        
    }
    
    public function httpRequest() {
        $http = new Zend_Controller_Request_Http();
        
        return $http;
    }
    
    public function baseUserLogin($id) {
        $session = new Zend_Session_Namespace(Admin_SecureController::$_NS);
        $baseUser = array();

        if (!isset($id) && isset($session->user->name)) {
            
            $baseUser['create_by'] = $session->user->name;
            $baseUser['create_on'] = date('Y-m-d H:i:s');
                        
        } else {
            $baseUser['update_by'] = $session->user->name;
            $baseUser['update_on'] = date('Y-m-d H:i:s');
        }
        
        return $baseUser;
    }
    
    public static function breadCrumb() {
        if (!is_object(self::$_bcObj)) {
            self::$_bcObj = Zend_Controller_Front::getInstance();
        }
        
        $module = self::$_bcObj->getRequest()->getModuleName();
        $controller = self::$_bcObj->getRequest()->getParam('controller');
        $action = self::$_bcObj->getRequest()->getParam('action');
        
        $link = '<a href="'.self::$_bcObj->getRequest()->getBaseUrl( $module ).'"></a> / ';
        $link .= '<a href="'.self::$_bcObj->getRequest()->getBaseUrl( $controller ).'"></a> / ';
        $link .= '<a href="'.self::$_bcObj->getRequest()->getBaseUrl( $action ).'"></a>';
        
        return $link;
    }
        
}

?>
